<template>
	<view class="wrap" :data-theme="theme()" :class="theme()" v-if="!loading">
		<!--tab-->
		<!-- 最新需求 fix 取消快递 -->
		<!-- <view class="top-tabbar" v-if="OrderData.delivery != 30">
			<block v-if="hasType(10)">
				<view :class="tab_type == 0 ? 'tab-item active' : 'tab-item'" @click="tabFunc(0)">快递配送</view>
			</block>
			<block v-if="hasType(20)">
				<view :class="tab_type == 1 ? 'tab-item active' : 'tab-item'" @click="tabFunc(1)">上门自提</view>
			</block>
		</view> -->
		<view class="p-0-23">
			<Myinfo :dis="options.orderType == 'retainage'" v-if="tab_type == 0 && OrderData.delivery != 30"
				:Address="Address" :existAddress="existAddress">
			</Myinfo>

			<Storeinfo v-if="tab_type == 1 && OrderData.delivery != 30" ref="getShopinfoData"
				:extractStore="extractStore" :OrderData='OrderData' :lastExtract="lastExtract"></Storeinfo>

			<!--购买的产品-->
			<view class="vender br6">
				<view class="list">
					<view class="d-b-c f24 fb mb30 top-title">
						<view>商品信息</view>
						<view>共{{ orderTotalNum }}件</view>
					</view>
					<view class="item" v-for="(item, index) in ProductData" :key="index">
						<view class="d-f">
							<view class="cover">
								<image :src="item.productImage" mode="aspectFit"></image>
							</view>
							<view class="info">
								<view class="d-b-s">
									<view class="flex-1">
										<view class="title f32 gray3">{{ item.productName }}</view>
										<view class="theme-price mt10 f18">
											¥<text class="f26">{{ item.productPrice }}</text>
										</view>
										<view class="theme-price mt10 f18">
											定金金额: <text class="f26">{{Number(item.depositPrice) }}元</text>&nbsp;
											定金比例: <text class="f26">{{Number(item.depositRatio)*100 }}%
												<text style="font-size: 16rpx;color:#1c2bb2">
													{{Number(item.depositRatio)<=0 ? '需支付全款':'可支付定金' }}</text>
											</text>
										</view>
										<view class="describe mt10 f24" v-if="options.orderType == 'deposit'">
											{{ item.advanceSku.productAttr }}
										</view>
										<view class="describe mt10 f24">{{
                      item.productSku.productAttr
                    }}</view>
									</view>


									<view>
										<view class="count_choose">
											<view class="num-wrap">
												<view class="f22 tr">×{{ item.totalNum }}</view>
											</view>
										</view>
									</view>
								</view>
							</view>
						</view>
						<view class="mt10 tr f28" v-if="item.isUserGrade == true">
							<text class="f26">会员折扣价：</text>
							<text class="theme-price f32">￥{{ item.gradeProductPrice }}</text>
						</view>
						<view class="mt10 tr f28" v-if="item.productReduceMoney > 0">
							<text class="f26">立减：</text>
							<text class="theme-price f32">￥{{ item.productReduceMoney }}</text>
						</view>
					</view>
				</view>
			</view>

			<!--其它费用-->
			<view class="buy-checkout br6">
				<template v-if="options.orderType == 'deposit'">
					<view class="d-f-c">
						<text class="key f26">定金：</text>
						<view class="f24">￥{{ OrderData.money }}</view>
					</view>
					<view class="item">
						<text class="key">配送费用：</text>
						<view>
							<text class="f24">￥{{ OrderData.expressPrice }}</text>
						</view>
					</view>
					<view class="d-f-c">
						<text class="key f26">尾款：</text>
						<view class="f24"> ￥{{ OrderData.balancePayment }}</view>
					</view>
					<view class="f-d-c p30">
						<view class="ww100 d-e-c red">(单件商品尾款已减{{ OrderData.reduceMoney }}元)
						</view>
						<view class="ww100 d-e-c gray9">
							{{ OrderData.advanceEndTime }}支付尾款
							<!-- {{supplier_item.productList[0].advance.active_time[0]}}-{{supplier_item.productList[0].advance.active_time[1]}}支付尾款 -->
						</view>
					</view>
				</template>
				<template v-else>
					<view class="item">
						<text class="key f26">商品金额：</text>
						<view class="f24">￥{{ OrderData.orderTotalPrice }}</view>
					</view>


					<view class="item">
						<text class="key">配送费用：</text>
						<view>
							<text class="f24">￥{{ OrderData.expressPrice }}</text>
						</view>
					</view>

					<view class="item" v-if="settledRule.isCoupon">
						<text class="key">优惠券：</text>
						<block v-if="couponList.length > 0">
							<view @click="onTogglePopupCoupon(couponList)"
								v-if="couponListRow && couponListRow.couponType == 40">
								【{{giftProduct && giftProduct.productName}}】送 {{totalNum}}株苗 <span style="color: #000;"> > </span>
							</view>
							<view v-else>
								<view class="f24 theme-price" v-if="OrderData.couponId > 0"
									@click="onTogglePopupCoupon(couponList)">-￥{{ OrderData.couponMoney }} <span style="color: #000;"> > </span> </view>
								<view v-else class="hascoupon" @click="onTogglePopupCoupon(couponList)">
									{{ couponList.length }}张可用<text class="icon iconfont icon-jiantou"></text>
								</view>
							</view>
						</block>
						<text v-else class="f24 gray9">无优惠券可用</text>
					</view>
					<view class="item">
						<text class="key">优惠券优惠价格：</text>
						<view>
							<text class="f24">￥{{ OrderData.couponMoney }}</text>
						</view>
					</view>
					<view class="item" v-if="userData && userData.points">
						<text class="key">可用积分：</text>
						<view style="display: flex;justify-content: flex-end;align-items: center;">
							<input style="max-width: 300rpx;text-align: right;" type="number" v-if="is_use_points == 1"
								class="userinfo_item_input" :placeholder="'当前可能积分为 '+ userData.points"
								v-model="pointsNum" />
							<switch :checked="is_use_points" style="transform: scale(0.7); margin-right: -10rpx"
								@change="onShowPoints" />
						</view>
					</view>
					<view class="item">
						<text class="key">积分优惠价格：</text>
						<view>
							<text class="f24">￥{{ OrderData.pointsMoney }}</text>
						</view>
					</view>

					<view class="item">
						<text class="key">优惠后价格：</text>
						<view>
							<text class="f24">￥{{ OrderData.orderPrice }}</text>
						</view>
					</view>
					<view class="item">
						<text class="key f26">定金金额：</text>
						<view class="f24">￥{{ OrderData.depositTotalPrice }}</view>
					</view>
					<view class="item" v-if="OrderData.packageTotalPrice && OrderData.packageTotalPrice != '0.00'" >
						<text class="key f26">包装费：</text>
						<view>
							<text class="f24">￥{{ OrderData.packageTotalPrice }}</text>
						</view>
					</view>
					<view class="item">
						<text class="key">尾款：</text>
						<view>
							<text class="theme-price f24">￥{{ OrderData.finalTotalPrice }}</text>
						</view>
					</view>
					

					<!-- <view class="item" v-if="OrderData.isAllowPoints && OrderData.pointsMoney > 0">
						<text class="key">可用积分抵扣：</text>
						<view class="">
							<text class="price">-￥{{ OrderData.pointsMoney }}</text>
							<switch :checked="is_use_points" style="transform: scale(0.7); margin-right: -10rpx"
								@change="onShowPoints" />
						</view>
					</view> -->
				</template>

				<view class="item">
					<view class="border-t-d9 d-e-c p-30-0 ww100">
						<text class="key f24">小计：</text>
						<view class="f38 fb"><text class="f24">￥</text>{{ toDecimal2(OrderData.orderPayPrice) }}</view>
					</view>
				</view>
			</view>
			<!--买家留言-->
			<view class="buyer-message uni-textarea">
				<textarea style="height: 150rpx;" class="textarea" v-model="remark" placeholder-style="color:#cccccc;"
					placeholder="选项:买家留言" />
			</view>
			<view class="affirm_rule">
				提交订单则代表你同意<text class="affirm_rule_user" @tap="protocol">《用户协议》</text>和<text class="affirm_rule_privacy"
					@tap="policy">《隐私政策》</text>
			</view>
		</view>
		<view class="buy-checkout" v-if="confirm && confirm != null">
			<view class="item" v-for="(item, index) in confirm" :key="index">
				<view style="white-space: nowrap">
					<span v-if="item.status" style="color: red">* </span>
					<span v-else style="margin-left: 18rpx"></span>
					<span>{{ item.title }}</span>
				</view>
				<!-- text -->
				<view v-if="item.label == 'text'" class="confirm">
					<input type="text" :placeholder="'请填写' + item.title" v-model="item.value" />
				</view>
				<!-- number -->
				<view v-if="item.label == 'number'" class="confirm">
					<input type="number" :placeholder="'请填写' + item.title" v-model="item.value" />
				</view>
				<!-- email -->
				<view v-if="item.label == 'email'" class="confirm">
					<input type="text" :placeholder="'请填写' + item.title" v-model="item.value" />
				</view>
				<!-- data -->
				<view v-if="item.label == 'data'" class="uni-list">
					<view class="uni-list-cell">
						<view class="uni-list-cell-db">
							<picker mode="date" :value="item.value" @change="bindDateChange($event, index)">
								<view v-if="item.value == ''" class="fontC f24">{{ date + item.title
                  }}<text class="iconfont icon-jiantou"></text></view>
								<view v-else class="uni-input f24">{{ item.value }}</view>
							</picker>
						</view>
					</view>
				</view>
				<!-- time -->
				<view v-if="item.label == 'time'">
					<view>
						<view>
							<picker mode="time" :value="item.value" start="00:00" end="23:59"
								@change="bindTimeChange($event, index)">
								<view v-if="item.value == ''" class="fontC">{{ time + item.title
                  }}<text class="iconfont icon-jiantou"></text></view>
								<view>{{ item.value }}</view>
							</picker>
						</view>
					</view>
				</view>
				<!-- id -->
				<view v-if="item.label == 'id'" class="confirm">
					<input type="idcard" :placeholder="'请填写' + item.title" v-model="item.value" />
				</view>
				<!-- phone -->
				<view v-if="item.label == 'phone'" class="confirm">
					<input type="tel" :placeholder="'请填写' + item.title" v-model="item.value" />
				</view>
				<!-- img -->
				<view v-if="item.label == 'img'" class="confirmImg">
					<view class="upload-list d-s-c">
						<view class="itemss" style="height: 136rpx" v-for="(imgs, img_num) in item.value" :key="img_num"
							@click="deleteImg(index, img_num)">
							<image :src="imgs.filePath" mode=""></image>
						</view>
						<view style="height: 136rpx" class="item upload-btn d-c-c d-c" @click="openUpload(index)"
							v-if="item.value.length < 9">
							<text class="icon iconfont icon-xiangji"></text>
							<text class="gray9" style="white-space: nowrap">上传图片</text>
						</view>
					</view>
				</view>
			</view>
		</view>

		<!--底部支付-->
		<view class="foot-pay-btns">
			<template v-if="options.orderType == 'deposit'">
				<view>
					应付
					<text class="fb theme-price">¥</text>
					<text class="num theme-price fb f38">{{ payDeposit() }}</text>
				</view>
			</template>
			<template v-else>
				<view v-if="!settledRule.forcePoints">
					应付
					<text class="fb theme-price">¥</text>
					<text class="num theme-price fb f38">{{
            OrderData.orderPayPrice
          }}</text>
				</view>
				<view class="price" v-if="settledRule.forcePoints">
					<text class="gray9">所需积分</text>
					<text class="num theme-price fb">{{ OrderData.pointsNum }}</text>
					<template v-if="OrderData.orderPayPrice > 0">
						<text class="theme-price">+</text>
						<text class="theme-price">¥</text>
						<text class="num fb theme-price">{{
              OrderData.orderPayPrice
            }}</text>
					</template>
				</view>
			</template>
			<!-- #ifdef  H5 -->
			<template v-if="isWeixin() && mpState == 1 && temlIds.length > 0">
				<wx-open-subscribe :template="temlIds" id="subscribe-btn" @success="subscribeSuccess"
					@error="subscribeFail" :style="{
            width: btnAtrrpx.width + 'px',
          }">
					<div v-is="'script'" type="text/wxtag-template" slot="style">
						<div v-is="'style'">
							.subscribe-btn.theme0{ background: #ff5704; }
							.subscribe-btn.theme1{ background: #19ad57; }
							.subscribe-btn.theme2{ background: #ffcc00; }
							.subscribe-btn.theme3{ background: #33a7ff; }
							.subscribe-btn.theme4{ background: #e4e4e4; }
							.subscribe-btn.theme5{ background: #c8ba97; }
							.subscribe-btn.theme6{ background: #623ceb; } .subscribe-btn {
							display:flex; width:100%; align-items:center;
							justify-content:center; color: #fff; border:none; }
						</div>
					</div>
					<div v-is="'script'" type="text/wxtag-template">
						<div class="subscribe-btn" :class="theme()" :style="{
                height: btnAtrrpx.height + 'px',
                lineHeight: btnAtrrpx.height + 'px',
                borderRadius: btnAtrrpx.borderRadius + 'px',
                fontSize: btnAtrrpx.fontSize + 'px',
              }">
							提交订单
						</div>
					</div>
				</wx-open-subscribe>
			</template>
			<template v-else>
				<button @click="SubmitOrder">提交订单</button>
			</template>
			<!-- #endif -->
			<!-- #ifndef  H5 -->
			<button @click="SubmitOrder">提交订单</button>
			<!-- #endif -->
		</view>
		<!-- 上传头像 -->
		<Upload v-if="isUpload" :num="1" @getImgs="getImgsFunc"></Upload>
		<!--优惠券-->
		<Coupon :isCoupon="isCoupon" :couponList="couponList" @close="closeCouponFunc"></Coupon>
		<!--支付-->
		<Checkout :isCheckout="isCheckout" :order_id="order_id" @close="closeCheckoutFunc"></Checkout>
		<!-- 选择弹窗 -->
		<selectProduct :isCoupon="isSelectProduct" :couponList="ProductData" @close="closeSelectProduct">
		</selectProduct>
	</view>
</template>

<script>
	import Myinfo from "./confirm-order/my-info.vue";
	import Storeinfo from "./confirm-order/store-info.vue";
	import Coupon from "./confirm-order/coupon.vue";
	import selectProduct from "./confirm-order/select-product.vue";
	import Upload from "@/components/upload/upload.vue";

	//#ifdef H5
	import jweixin from "weixin-js-sdk";
	//#endif
	import Checkout from "./checkout";
	export default {
		components: {
			Myinfo,
			Storeinfo,
			Coupon,
			Checkout,
			Upload,
			selectProduct
		},
		data() {
			return {
				confirm: "",
				/*是否加载完成*/
				loading: true,
				options: {},
				indicatorDots: true,
				isUpload: false,
				autoplay: true,
				interval: 2000,
				duration: 500,
				tab_type: 1, // 默认显示自提 且不需要显示快递
				/*商品id*/
				product_id: "",
				/*商品数量*/
				product_num: "",
				/*商品数据*/
				ProductData: [],
				/*订单数据数据*/
				OrderData: [],
				/*结算规则*/
				settledRule: {},
				// 是否存在收货地址
				existAddress: false,
				/*默认地址*/
				Address: {
					region: [],
				},
				extractStore: [],
				lastExtract: {},
				product_sku_id: 0,
				/*配送方式*/
				delivery: 20, // 自提
				/*自提店id*/
				storeId: 0,
				/*优惠券id*/
				coupon_id: 0,
				/*是否使用积分*/
				is_use_points: 0,
				linkman: "",
				phone: "",
				remark: "",
				/*支付方式*/
				pay_type: 20,
				/*是否显示优惠券*/
				isCoupon: false,
				couponId: 0,
				/*优惠券列表*/
				couponList: [],
				deliverySetting: [],
				/*优惠券数量*/
				coupon_num: 0,
				/*消息模板*/
				temlIds: [],
				// 支付相关
				isCheckout: false,
				date: "请选择",
				time: "请选择",
				defaultDate: "",
				defaultTime: "",
				order_id: 0,
				order_type: "",
				orderTotalNum: 0, //商品数量
				url: "",
				btnAtrrpx: {},
				// 1 公众号登录
				mpState: null,
				depositValue: 0,
				isSelectProduct: false,
				giftProduct: null,
				couponListRow: null,
				totalNum: 0,
				userData: {},
				pointsNum: '',
				orderAddress: '',
				addressId: '',
				productType: ''
			};
		},
		watch: {
			pointsNum: {
				handler(v) {
					this.getData();
				}
			}
		},

		onLoad(options) {
			let self = this;
			let mpState = uni.getStorageSync("mpState");
			this.mpState = mpState;
			// 公众号分享
			if (this.getPlatform() == "mp") {
				this.url = window.location.href;
			}
			self.options = options;
			console.log(options, 'options1111111111111111111111111')
			this.getData();
			self.$fire.on("selectStoreId", function(store) {
				self.storeId = store.storeId;
				self.extractStore = store;
			});
			self.$fire.on("extract", function(params) {
				self.lastExtract = params;
			});
			let btnAtrrpx = {
				height: 80,
				borderRadius: 40,
				fontSize: 32,
				width: 200,
			};
			uni.getSystemInfo({
				success: function(res) {
					let scale = res.screenWidth / 750;
					let newObj = {};
					for (let key in btnAtrrpx) {
						newObj[key] = btnAtrrpx[key] * scale;
					}
					self.btnAtrrpx = newObj;
				},
				fail() {
					self.btnAtrrpx = btnAtrrpx;
				},
			});
		},
		onShow() {
			//#ifdef H5
			this.getTemplateId();
			//#endif
			if (uni.getStorageSync('orderAddress')) {
				this.orderAddress = JSON.parse(uni.getStorageSync('orderAddress'));
				console.log(this.orderAddress, 'orderAddress')
				setTimeout(() => {
					this.Address = this.orderAddress;
					this.addressId = this.orderAddress.addressId;
				}, 1500)
			}

		},
		methods: {
			// 跳转到用户协议
			protocol() {
				uni.navigateTo({
					url: '/orderpages/order/userProtocol',
				});
			},
			// 跳转到隐私政策
			policy() {
				uni.navigateTo({
					url: '/orderpages/order/policy',
				});
			},
			openUpload(index) {
				this.index = index;
				this.isUpload = true;
			},
			/*获取上传的图片*/
			getImgsFunc(e) {
				let self = this;
				if (e && typeof e != "undefined") {
					let index = self.index;
					self.confirm[index].value = self.confirm[index].value.concat(e);
				}
				self.isUpload = false;
			},
			/*点击图片删除*/
			deleteImg(i, n) {
				this.confirm[i].value.splice(n, 1);
			},
			bindDateChange: function(e, index) {
				console.log(e, "e");
				this.confirm[index].value = e.detail.value;
			},
			bindTimeChange: function(e, index) {
				this.confirm[index].value = e.detail.value;
			},
			subscribeSuccess() {
				this.SubmitOrder();
				console.log("调用成功");
			},
			subscribeFail() {
				this.SubmitOrder();
				console.log("调用失败");
			},
			payDeposit() {
				return (
					parseFloat(this.OrderData.money) +
					((this.orderData && this.orderData.expressPrice) || 0)
				);
			},
			/**/
			hasType(e) {
				if (this.deliverySetting.indexOf(e) != -1) {
					return true;
				} else {
					return false;
				}
			},
			/*是否使用积分选择*/
			onShowPoints: function(e) {
				let self = this;
				if (e.detail.value == true) {
					self.is_use_points = 1;
				} else {
					self.is_use_points = 0;
				}
				self.getData();
			},
			/*选择优惠卷*/
			onTogglePopupCoupon(e) {
				let self = this;
				self.isCoupon = true;
				self.couponList = e;
			},
			/*关闭优惠券*/
			closeCouponFunc({
				row,
				e
			}) {
				console.log(row, e, 'werrew')
				this.isCoupon = false;
				// if (e == null) {
				// 	return;
				// }
				this.giftProduct = null;
				this.couponList = [];
				this.couponListRow = {}
				if (row == 40) {
					this.isSelectProduct = true;
				} else {
					let self = this;
					self.couponId = e || 0;
					self.getData();
				}


			},
			closeSelectProduct({
				row,
				e
			}) {
				console.log(row, 'closeSelectProduct')
				this.giftProduct = row;
				console.log(uni.getStorageSync('couponListRow'),'2345')
				this.couponListRow = JSON.parse(uni.getStorageSync('couponListRow'));
				this.couponId = this.couponListRow.userCouponId || ''
				this.options.orderType === "cart"
				// 组装数据
				this.getData();
				this.isSelectProduct = false;
			},
			/*获取数据*/
			getData() {
				let self = this;
				uni.showLoading({
					title: "加载中",
				});
				let callback = function(res) {
					if (res.data.user) {
						self.userData = res.data.user
					}

					res.data.giftProduct && (self.totalNum = res.data.giftProduct.totalNum)
					self.orderTotalNum = res.data.orderTotalNum;
					self.OrderData = res.data.orderData;
					self.temlIds = res.data.templateArr;
					self.existAddress = self.OrderData.existAddress;
					self.Address = self.OrderData.address;
					self.OrderData.address && (self.addressId = self.OrderData.address.addressId);
					self.extractStore = self.OrderData.extractStore;
					if (self.extractStore == null) {
						self.extractStore = {};
					}
					self.lastExtract = self.OrderData.lastExtract;
					self.settledRule = res.data.settledRule;
					self.ProductData = res.data.productList;
					self.depositTotalPrice = res.data.depositTotalPrice
					self.ProductData.forEach((product) => {
						self.confirm = product.customForm;
					});
					if (self.confirm) {
						self.confirm.map((e) => {
							if (e.label === "img") e.value = [];
						});
					}
					
					// if (res.data.couponList) {
						self.couponList = res.data.couponList;
					// }
					self.delivery = self.OrderData.delivery;
					if (self.OrderData.delivery == 20) {
						self.tab_type = 1;
					}
					self.deliverySetting = self.OrderData.deliverySetting;
					if (self.OrderData.order_pay_price == 0) {
						self.pay_type = 10;
					}
					self.loading = false;
				};

				// 请求的参数
				let params = {
					delivery: self.delivery, //配送方式
					storeId: self.storeId, // 自提店id
					couponId: self.couponId, //优惠券id 
					isUsePoints: self.is_use_points, //是否使用积分
					paySource: self.getPlatform(), //平台
					giftProduct: self.giftProduct,
					pointsNum: self.is_use_points == 1 ? Number(self.pointsNum) : 0
				};

				//直接购买
				if (self.options.orderType === "buy" || self.options.orderType === "assemble" || self.options.orderType ===
					"bargain" || self.options.orderType === "seckill" || self.options.orderType == "points") {
					self._postBody(
						"order/order/toBuy",
						Object.assign({}, params, {
							productId: self.options.productId,
							productNum: self.options.productNum,
							specSkuId: self.options.specSkuId,
							batchId: self.options.batchId,
							activityId: self.options.activityId,
							url: self.url,
						}),
						function(res) {
							const {
								data
							} = res;
							console.log(data.orderData.productType, 'data.orderData.productType')
							self.productType = data.orderData.productType || ''
							callback(res);
						},
						(err) => {
							uni.navigateBack();
						}
					);
				}
				//定金
				if (self.options.orderType === "deposit") {
					let test = Object.assign({}, params, {
						productId: self.options.productId,
						productNum: self.options.productNum,
						productSkuId: self.options.productSkuId,
						advanceProductSkuId: self.options.advanceProductSkuId,
						advanceProductId: self.options.advanceProductId,
					});
					self._postBody(
						"plus/advance/order/frontBuy",
						test,
						function(res) {
							callback(res);
						},
						(err) => {
							uni.navigateBack();
						}
					);
				}
				//尾款
				if (self.options.orderType === "retainage") {
					self._get(
						"plus/advance.Order/buy",
						Object.assign({}, params, {
							order_id: self.options.order_id,
						}),
						function(res) {
							callback(res);
						},
						(err) => {
							uni.navigateBack();
						}
					);
				}
				// 购物车结算
				else if (self.options.orderType === "cart") {
					const ids = self.options.cartIds
					const postObj = {
						...params,
						productList: []
					}
					const arrys = ids.split(',')
					arrys.forEach(item => {
						if (item) {
							const values = item.split('_')
							const json = {
								productId: values[0],
								skuId: values[1],
								batchId: values[2] == "null" ? null : values[2],
								activityId: values[3] == "null" ? null : values[3]
							}
							postObj.productList.push(json)
						}
					})
					self._postBody("order/order/toCart", postObj,
						function(res) {
							callback(res);
						},
						(err) => {
							uni.navigateBack();
						}
					)
				}



			},

			getTemplateId() {
				let self = this;
				self._postBody(
					"index/getSignPackage", {
						url: self.url,
						paySource: self.getPlatform(),
					},
					function(res) {
						// self.temlIds = res.data.templateArr;
						self.mpMessage(res.data.signPackage);
					}
				);
			},

			/*选择配送方式*/
			tabFunc(e) {
				if (this.options.orderType == "retainage") {
					return;
				}
				this.tab_type = e;
				if (e == 0) {
					// 配送
					this.delivery = 10;
				} else {
					// 自提
					this.delivery = 20;
				}

				this.getData();
			},

			/*提交订单*/
			SubmitOrder() {

				let self = this;
				uni.showLoading({
					title: "加载中",
					mask: true,
				});
				console.log(self.confirm, "confirmsss");
				if (this.pointsNum && (this.pointsNum > this.userData.points)) {
					return uni.showToast({
						title: `请输入小于或等于当前积分数`,
						icon: "none",
					});
				}
				if (this.confirm) {
					for (var i = 0; i < this.confirm.length; i++) {
						console.log(this.confirm[i], "confirm");
						let self = this.confirm[i];
						console.log(self, "self");
						if (self.status) {
							if (
								self.label === "text" ||
								self.label === "data" ||
								self.label === "time" ||
								self.label === "id"
							) {
								if (!self.value.trim()) {
									return uni.showToast({
										title: `请输入` + `${self.title}`,
										icon: "none",
									});
								}
							}
							if (self.label === "number") {
								if (self.value <= 0) {
									return uni.showToast({
										title: `请输入` + `${self.title}`,
										icon: "none",
									});
								}
							}
							if (self.label === "email") {
								if (
									!/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test(
										self.value
									)
								) {
									return uni.showToast({
										title: `请输入正确的` + `${self.title}`,
										icon: "none",
									});
								}
							}
							if (self.label === "phone") {
								if (!/^1(3|4|5|7|8|9|6)\d{9}$/i.test(self.value)) {
									return uni.showToast({
										title: `请输入正确的` + `${self.title}`,
										icon: "none",
									});
								}
							}
							if (self.label === "img") {
								if (!self.value.length > 0) {
									return uni.showToast({
										title: `请上传` + `${self.title}`,
										icon: "none",
									});
								}
							}
						}
					}
				}
				let params = {
					delivery: self.delivery,
					storeId: self.storeId || 0, // 自提点id
					couponId: self.couponId,
					isUsePoints: self.is_use_points,
					phone: self.lastExtract.phone,
					linkman: self.lastExtract.linkman,
					remark: self.remark,
					customForm: self.confirm,
					addressId: self.addressId, //地址id
					paySource: self.getPlatform(), //平台
					giftProduct: self.giftProduct,
					pointsNum: self.is_use_points == 1 ? Number(self.pointsNum) : 0,
					batchId: self.options.batchId,
					activityId: self.options.activityId,
				};
				// uni.setStorageSync('SubmitOrderParams', JSON.stringify(params));
				// 创建订单-直接下单
				let url = "";
				if (self.options.orderType === "buy") {
					url = "order/order/buy";
					params = Object.assign(params, {
						productId: self.options.productId,
						productNum: self.options.productNum,
						specSkuId: self.options.specSkuId,
					});
				}
				//定金
				if (self.options.orderType === "deposit") {
					url = "plus/advance/order/buy";
					params = Object.assign(params, {
						productId: self.options.productId,
						productNum: self.options.productNum,
						productSkuId: self.options.productSkuId,
						advanceProductSkuId: self.options.advanceProductSkuId,
						advanceProductId: self.options.advanceProductId,
					});
				}
				//尾款
				if (self.options.orderType === "retainage") {
					url = "plus/advance/Order/buy";
					params = Object.assign(params, {
						order_id: self.options.order_id,
					});
				}
				// 创建订单-购物车结算
				if (self.options.orderType === "cart") {
					const ids = self.options.cartIds
					const postObj = {
						...params,
						productList: []
					}
					const arrys = ids.split(',')
					arrys.forEach(item => {
						if (item) {
							const values = item.split('_')
							const json = {
								productId: values[0],
								skuId: values[1],
								batchId: values[2] == "null" ? null : values[2],
								activityId: values[3] == "null" ? null : values[3]
							}
							postObj.productList.push(json)
						}
					})
					url = "order/order/cart";
					params = Object.assign(postObj, {
						cartIds: self.options.cartIds || 0,
					});
				}

				// 创建订单-积分兑换
				if (self.options.orderType === "points") {
					url = "plus/points/order/buy";
					params = Object.assign(params, {
						pointProductId: self.options.pointProductId,
						pointProductSkuId: self.options.pointProductSkuId,
						productSkuId: self.options.productSkuId,
						productNum: self.options.productNum,
					});
				}
				// 创建订单-限时秒杀
				if (self.options.orderType === "seckill") {
					url = "plus/seckill/order/buy";
					params.num = self.options.num;
					params = Object.assign(params, {
						seckillProductId: self.options.seckillProductId,
						productSkuId: self.options.productSkuId,
						seckillProductSkuId: self.options.seckillProductSkuId,
						productNum: self.options.productNum,
					});
				}
				// 创建订单-砍价
				if (self.options.orderType === "bargain") {
					url = "plus/bargain/order/buy";
					params = Object.assign(params, {
						bargainProductId: self.options.bargainProductId,
						productSkuId: self.options.productSkuId,
						bargainProductSkuId: self.options.bargainProductSkuId,
						bargainTaskId: self.options.bargainTaskId,
					});
				}

				// 创建订单-限时拼团
				if (self.options.orderType === "assemble") {
					url = "plus/assemble/order/buy";
					params = Object.assign(params, {
						assembleProductId: self.options.assembleProductId,
						productSkuId: self.options.productSkuId,
						assembleProductSkuId: self.options.assembleProductSkuId,
						assembleBillId: self.options.assembleBillId,
						productNum: self.options.productNum,
					});
				}
				let callback = function() {
					self._postBody(url, params, function(res) {
						// 拼团活动不需要支付
						// if (self.productType == 7 || self.productType == 8) {
						// 	uni.showToast({
						// 		title: '操作成功',
						// 		icon: 'none',
						// 		duration: 1500
						// 	});
						// 	setTimeout(() => {
						// 		uni.redirectTo({
						// 			url: '/orderpages/order/myorder'
						// 		})
						// 	}, 2000)
						// } else {
							let pages = "/orderpages/order/cashier?orderId=" + res.data;
							if (self.options.orderType == "deposit") {
								pages = "/orderpages/order/cashier?orderType=40&orderId=" + res.data;
							}
							self.gotoPage(pages, "reLaunch");
						// }
					});
				};
				uni.setStorageSync('couponListRow', '');
				uni.setStorageSync('orderAddress', '');
				self.subMessage(self.temlIds, callback);
			},
			toDecimal2(x) {
				var f = parseFloat(x);
				if (isNaN(f)) {
					return "0.00";
				}
				var f = Math.round(x * 100);
				var n = Math.round(x * 1000);
				var r = n.toString().split("");
				r = r[r.length - 1];
				if (r >= 5) {
					f = (f - 1) / 100;
				} else {
					f = f / 100;
				}
				var s = f.toString();
				var rs = s.indexOf(".");
				if (rs < 0) {
					rs = s.length;
					s += ".";
				}
				while (s.length <= rs + 2) {
					s += "0";
				}
				return s;
			},
			closeCheckoutFunc() {
				this.isCheckout = false;
			},
		},
	};
</script>

<style lang="scss" scoped>
	.affirm_rule {
	  font-size: 24rpx;
	  font-family: PingFangSC-Regular, PingFang SC;
	  font-weight: 400;
	  color: #999999;
	  line-height: 34rpx;
	  margin: 20rpx;
	}
	.affirm_rule_user {
	  color: #077840;
	}
	.affirm_rule_privacy {
	  color: #077840;
	}
	.info-image {
		width: 112rpx;
		height: 112rpx;
		border-radius: 10rpx;

		image {
			width: 112rpx;
			height: 112rpx;
			border-radius: 10rpx;
		}
	}

	.weixinBtn {
		float: right;
	}

	page {
		background-color: #f2f2f2;
	}

	.f-d-c {
		flex-direction: column;
	}

	.wrap {
		padding-bottom: 110rpx;
	}

	.d-f-c {
		display: flex;
		justify-content: space-between;
		align-items: center;
		overflow: hidden;
		padding: 30rpx;
		border-bottom: 1rpx solid #d9d9d9;
	}

	.dfjac {
		display: flex;
		align-items: center;
	}

	.d-txar {
		white-space: nowrap;
		width: 200px;
		margin-right: 34rpx;
	}

	.extp {
		color: #9e9e9e;
		margin-left: 34rpx;
	}

	.vender .list .item {
		border-bottom: none;
	}

	.vender .top-title {
		padding: 30rpx 25rpx;
	}

	.icon-jiantou {
		margin-left: 15rpx;
	}

	.icon-dianpu1 {
		margin-right: 15rpx;
		font-size: 28rpx;
		color: #333333;
	}

	.sup_itemtit {
		padding: 40rpx 30rpx;
		display: flex;
		align-items: center;
	}

	.vender .total-box {
		height: 87rpx;
		line-height: 87rpx;
		border-bottom: 16rpx solid #f2f2f2;
	}

	.d-f {
		display: flex;
	}

	.zt {
		padding: 2rpx 10rpx;
		margin-right: 10rpx;
		background: #e2231a;
		color: #ffffff;
		border-radius: 8rpx;
		font-size: 22rpx;
	}

	.icon-box .icon-zhifubao {
		color: #1296db;
		font-size: 50rpx;
	}

	.icon-dianpu1 {}

	.text_area {
		width: 100%;
		height: 120rpx;
		background: #f2f2f2;
		border-radius: 6rpx;
		padding: 20rpx;
		box-sizing: border-box;
		font-size: 24rpx;
	}

	.icon-xuanze {
		font-size: 38rpx;
	}

	.tab-item {
		font-size: 28rpx;
		color: #333333;
		font-weight: 400;
	}

	.tab-item.active {
		font-size: 28rpx;
		color: #333333;
		font-weight: 400;
	}

	.tab-item.active::after {
		width: 115rpx;
		height: 6rpx;
	}

	.hascoupon {
		padding: 0 18rpx;
		box-sizing: border-box;
		height: 38rpx;
		line-height: 38rpx;
		border-radius: 200rpx;
		color: #ffffff;
		background: linear-gradient(180deg, #fc4133, #ff7a04);
		font-size: 20rpx;

		.icon.icon-jiantou {
			color: #ffffff;
			font-size: 20rpx;
			margin-left: 2rpx;
		}
	}

	.buy-checkout {
		.item {
			padding: 16rpx 30rpx;
			border-bottom: none;
		}
	}

	.confirm {
		text-align: right;
		font-size: 22rpx;
	}

	.buy-checkout .item {
		border-radius: 15rpx;
		overflow: hidden;
	}

	.confirmImg {
		padding-top: 60rpx;
		width: 100%;

		.img {
			width: 136rpx;
			height: 136rpx;
		}

		.pictrue {
			width: 136rpx;
			height: 136rpx;
			box-sizing: border-box;
			margin: 18rpx;
			margin-bottom: 35rpx;
			position: relative;
			font-size: 22rpx;
			color: #bbb;

			.del {
				position: absolute;
				top: 0;
				right: 0;
			}
		}

		.bor {
			border: 1rpx solid #ddd;
		}
	}

	.itemss {
		margin-right: 20rpx;
		margin-bottom: 20rpx;
		width: 136rpx;

		image {
			width: 136rpx;
			height: 136rpx;
			border-radius: 15rpx;
		}
	}

	.upload-btn {
		width: 136rpx;
		height: 136rpx;
		margin: 0;
		margin-right: 20rpx;
		margin-bottom: 20rpx;
		box-sizing: border-box;
		display: flex;
		justify-content: center;
		align-items: center;
		flex-direction: column;
	}

	.order-submission .wrapper {
		background-color: #fff;
		margin-top: 13rpx;
	}

	.order-submission .wrapper .item {
		padding: 27rpx 30rpx;
		font-size: 30rpx;
		color: #282828;
		border-bottom: 1px solid #f0f0f0;

		.mark {
			background-color: #f9f9f9;
			// width: 345px;
			min-height: 70px;
			border-radius: 1px;
			margin-top: 15px;
			padding: 12px 14px;
			color: #ccc;
			font-size: 28rpx;
			box-sizing: border-box;
		}

		.mark-msg {
			color: #333;
			font-size: 28rpx;
		}
	}

	.order-submission .wrapper .item .discount {
		font-size: 30rpx;
		color: #999;
	}

	.order-submission .wrapper .item .discount input {
		text-align: end;
	}

	.order-submission .wrapper .item .discount .iconfont {
		color: #515151;
		font-size: 30rpx;
		margin-left: 15rpx;
	}

	.order-submission .wrapper .item .discount .num {
		font-size: 32rpx;
		margin-right: 20rpx;
	}

	.order-submission .wrapper .item .shipping {
		font-size: 30rpx;
		color: #999;
		position: relative;
		padding-right: 58rpx;
	}

	.order-submission .wrapper .item .shipping .iconfont {
		font-size: 35rpx;
		color: #707070;
		position: absolute;
		right: 0;
		top: 50%;
		transform: translateY(-50%);
		margin-left: 30rpx;
	}

	.order-submission .wrapper .item textarea {
		background-color: #f9f9f9;
		width: 100%;
		height: 135rpx;
		border-radius: 3rpx;
		margin-top: 30rpx;
		padding: 25rpx 28rpx;
		font-size: 28rpx;
		box-sizing: border-box;
	}

	.order-submission .wrapper .item .placeholder {
		color: #ccc;
		font-size: 28rpx;
	}

	.order-submission .wrapper .item .list {
		margin-top: 35rpx;
	}

	.order-submission .wrapper .item .list .payItem {
		border: 1px solid #eee;
		border-radius: 6rpx;
		height: 86rpx;
		width: 100%;
		box-sizing: border-box;
		margin-top: 20rpx;
		font-size: 28rpx;
		color: #282828;
	}

	.order-submission .wrapper .item .list .payItem.on {
		border-color: #fc5445;
		color: #e93323;
	}

	.order-submission .wrapper .item .list .payItem .name {
		width: 50%;
		text-align: center;
		border-right: 1px solid #eee;
		padding-left: 80rpx;
	}

	.order-submission .wrapper .item .list .payItem .name .iconfont {
		width: 44rpx;
		height: 44rpx;
		border-radius: 50%;
		text-align: center;
		line-height: 44rpx;
		background-color: #fe960f;
		color: #fff;
		font-size: 30rpx;
		margin-right: 15rpx;
	}

	.order-submission .wrapper .item .list .payItem .name .iconfont.icon-weixin2 {
		background-color: #41b035;
	}

	.order-submission .wrapper .item .list .payItem .name .iconfont.icon-zhifubao {
		background-color: #1677ff;
	}

	.order-submission .wrapper .item .list .payItem .tip {
		width: 49%;
		text-align: center;
		font-size: 28rpx;
		color: #aaa;
	}

	.acea-row {
		display: -webkit-box;
		display: -moz-box;
		display: -webkit-flex;
		display: -ms-flexbox;
		display: flex;
		-webkit-box-lines: multiple;
		-moz-box-lines: multiple;
		-o-box-lines: multiple;
		-webkit-flex-wrap: wrap;
		-ms-flex-wrap: wrap;
		flex-wrap: wrap;
	}

	.acea-row.row-between-wrapper {
		-webkit-box-align: center;
		-moz-box-align: center;
		-o-box-align: center;
		-ms-flex-align: center;
		-webkit-align-items: center;
		align-items: center;
		-webkit-box-pack: justify;
		-moz-box-pack: justify;
		-o-box-pack: justify;
		-ms-flex-pack: justify;
		-webkit-justify-content: space-between;
		justify-content: space-between;
	}

	.fontC {
		color: grey;
	}
</style>